package com.location.footprint.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.location.footprint.R;
import com.location.footprint.base.BaseAppAplication;
import com.location.footprint.eventbus.EventBusUtils;
import com.location.footprint.eventbus.EventMessage;
import com.location.footprint.toolbar.QMUIStatusBarHelper;
import com.location.footprint.utils.LogUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;

public abstract class BaseActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);
        if (isRegisteredEventBus()) {
            EventBusUtils.register(this);
        }
        initView();
        initData();
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (BaseAppAplication.theme == R.color.white) {
            QMUIStatusBarHelper.setStatusBarLightMode(this);
        } else {
            QMUIStatusBarHelper.setStatusBarDarkMode(this);

        }

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (isRegisteredEventBus()) {
            EventBusUtils.unregister(this);
        }
        release();
    }

    /**
     * 获取布局
     *
     * @return 布局 ID
     */
    protected abstract int getLayoutId();

    /**
     * 初始化视图
     */
    protected void initView() {
    }

    /**
     * 初始化数据
     */
    protected void initData() {
    }

    /**
     * 释放资源
     */
    protected void release() {
    }

    /**
     * 是否注册事件分发
     *
     * @return true 注册；false 不注册，默认不注册
     */
    protected boolean isRegisteredEventBus() {
        return false;
    }

    /**
     * 接收到分发的事件
     *
     * @param event 事件
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveEvent(EventMessage event) {
    }

    /**
     * 接受到分发的粘性事件
     *
     * @param event 粘性事件
     */
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onReceiveStickyEvent(EventMessage event) {
    }
}
